Advertisement
Guest User

Untitled

a guest
Dec 8th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.96 KB | None | 0 0
  1. static public string ForceJson(object res)
  2.     {
  3.         JavaScriptSerializer js = new JavaScriptSerializer();
  4.         return ( js.Serialize(res) );
  5.     }
  6.  
  7.     static public byte[] Hash(string plainString, Encoding encoding)
  8.     {
  9.       if (plainString == null)
  10.         throw new ArgumentNullException("plainString");
  11.  
  12.       if (encoding == null)
  13.         encoding = Encoding.UTF8;
  14.  
  15.       return Hash(encoding.GetBytes(plainString));
  16.     }
  17.  
  18.     static public byte[] Hash(byte[] bytes)
  19.     {
  20.       if (bytes == null)
  21.         throw new ArgumentNullException("bytes");
  22.       using (SHA256 algorithm = new SHA256Managed())
  23.       {
  24.         byte[] hashBytes = algorithm.ComputeHash(bytes);
  25.         return hashBytes;
  26.       }
  27.     }
  28.  
  29.     public string HashToBase64(string plainString, Encoding encoding)
  30.     {
  31.       if (plainString == null) throw new ArgumentNullException("plainString");
  32.       return Convert.ToBase64String(Hash(plainString, encoding));
  33.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement